package com.example.utils;

import com.example.c3p0.C3P0DataSource;

/**
 * @Classname DataSourceUtils
 * @Description TODO
 * @Date 2022/5/27 13:46
 * @Created by XiongXiong
 * @Author: X.I.O
 */
public class DataSourceUtils {

    public static void init(){
        String url=PropertiesUtils.getProperty("url");
        String driver=PropertiesUtils.getProperty("driver");
        String username=PropertiesUtils.getProperty("username");
        String password = PropertiesUtils.getProperty("password");
        C3P0DataSource c3P0DataSource=initDataSource(url,driver,username,password);
        ObjectMaps.setAutuWirdemap(C3P0DataSource.class.getName(),c3P0DataSource);
    }

    private static C3P0DataSource initDataSource(String url, String driver, String username, String password){
        C3P0DataSource c3P0DataSource = new C3P0DataSource(url, driver, password, username);
        return c3P0DataSource;
    }

    public static C3P0DataSource getC3P0DataSource(){
        C3P0DataSource c3P0DataSource=(C3P0DataSource)ObjectMaps.getObjectByClass(C3P0DataSource.class);
        return c3P0DataSource;
    }
}
